﻿using InnoWeb.CEND.BL.Service.iThink;
using InnoWeb.CEND.Core.Framework;
using InnoWeb.CEND.Core.Model.iThink;
using InnoWeb.CEND.Data;
using InnoWeb.CEND.Data.Infrastructure;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Mvc;

namespace InnoWeb.CEND.UI.MVC.Controllers
{
    public class BaseController : Controller
    {
        private const string connectionString = @"Server=N04155-1013\OMERSRV;Database=CendDB;Trusted_Connection=True;";

        private static WebSiteContext _context;
        private static IUnitOfWork _unitOfWork;

        private static GenericRepository<iThinkMenuItems> _iThinkMenuItemsRepository;
        private static iThinkMenuItemService _iThinkMenuItemsService;

        protected override void ExecuteCore()
        {
            //string cultureName = string.Empty;

            //HttpCookie cultureCookie = Request.Cookies["_culture"];
            //if (cultureCookie != null)
            //    cultureName = cultureCookie.Value;
            //else
            //    cultureName = Request.UserLanguages[0];

            //cultureName = CultureHelper.GetImplementedCulture(cultureName);

            //Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cultureName);
            //Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;

            base.ExecuteCore();
        }

        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            _context = new WebSiteContext(ConfigurationManager.ConnectionStrings["CendDBConnection"].ConnectionString);
            _unitOfWork = new UnitOfWork(_context);

            _iThinkMenuItemsRepository = new GenericRepository<iThinkMenuItems>(_context);
            _iThinkMenuItemsService = new iThinkMenuItemService(_unitOfWork, _iThinkMenuItemsRepository);

            var list = _iThinkMenuItemsService.GetAllElements();

            ViewBag.menuList = list;

            base.Initialize(requestContext);
        }
    }
}
